package com.numberone.web.controller.xycard;


import java.util.Random;

public class CardCodeFactory {
    /** 卡号总长度 */
    private static final int maxLength = 14;

    private static final int maxPwdLength = 6;

    public String toCode() {
        StringBuilder idsbs = new StringBuilder();
        return idsbs.append(getRandom(maxLength)).toString();
    }

    /**
     * 生成固定长度随机码
     * @param n    长度
     */
    private  long getRandom(long n) {
        long min = 1,max = 9;
        for (int i = 1; i < n; i++) {
            min *= 10;
            max *= 10;
        }
        long rangeLong = (((long) (new Random().nextDouble() * (max - min)))) + min ;
        return rangeLong;
    }

    public String toPwd() {
        StringBuilder idsbs = new StringBuilder();
        return idsbs.append(getRandom(maxPwdLength)).toString();
    }
}
